<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var names = ["abc", "cba", "nba", "mba"]
    console.log(names.indexOf("nba")) // 2
    console.log(names.indexOf("why")) // -1

    var students = [
      { id: 100, name: 'why', age: 18 },
      { id: 101, name: 'kobe', age: 30 },
      { id: 102, name: 'james', age: 25 },
      { id: 103, name: 'why1', age: 22 },
    ]
    var stu = null
    for (var i = 0; i < students.length; i++) {
      if (students[i].id === 101) {
        stu = students[i]
        console.log(stu)
        break
      }
    }
    if (stu) {
      console.log("找到了对应的101学生")
    } else {
      console.log("没有找到对应的101学生")
    }

    var stu = students.find(function (item) {
      if (item.id === 101) return true
    })
    console.log(stu)
    
    var stu1 = students.find(item => item.id === 101)
    console.log(stu1)

  </script>
</body>

</html>